package com.nidu.demo.tenant.executor.query;

import com.alibaba.cola.dto.PageResponse;
import com.nidu.demo.tenant.convertor.TenantPackageCriteriaConvertor;
import com.nidu.demo.tenant.dto.TenantPackagePageQry;
import com.nidu.demo.tenant.convertor.TenantPackageConvertor;
import com.nidu.demo.tenant.dto.TenantPackageCO;
import com.nidu.demo.tenant.gateway.TenantPackageGateway;
import com.nidu.demo.tenant.model.TenantPackage;
import com.nidu.demo.tenant.model.TenantPackageCriteria;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 租户套餐分页查询执行器
 *
 * @author auto
 */
@Component
@RequiredArgsConstructor
public class TenantPackagePageQryExe {

    private final TenantPackageGateway gateway;

    private final TenantPackageConvertor convertor;

    private final TenantPackageCriteriaConvertor criteriaConvertor;

    public PageResponse<TenantPackageCO> execute(TenantPackagePageQry qry) {
        // 1. 查询数据
        TenantPackageCriteria criteria = criteriaConvertor.toDataObject(qry);
        PageResponse<TenantPackage> page = gateway.pageByCondition(criteria);

        // 2. 转换为DTO返回
        List<TenantPackageCO> tenantPackageCOS = convertor.toClientObjects(page.getData());
        return PageResponse.of(tenantPackageCOS, page.getTotalCount(), page.getPageSize(), page.getPageIndex());
    }
}